home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / iaca101.zip / IACAREAD.C < prev    next >
Text File  |  1991-11-10  |  2KB  |  72 lines

  1. /*    iacaread - looks for a string in memory at 40:f0 and sets an environment
  2.     variable to the value found there.  Name of variable to set is entered
  3.     on the command line.  Purpose of this routine is to pass information
  4.     from CONFIG.SYS to AUTOEXEC.BAT.  A companion device driver IACAFILL.ASM
  5.     sets the value at 40:f0.
  6.  
  7.     This routine uses a collection of environment-handling routines which were
  8.     written by John Lowenthal (BIX: jlowenthal) and donated by OPENetwork to
  9.     the public domain.  The code to find the master enviroment traces back to
  10.     a message posted on BIX by P. Maupin.
  11.  
  12.     This main program and the companion IACAFILL.ASM are Copyright 1991 by
  13.     Robert W. Babcock and WSS Division of DDC
  14.     4 Reeves Road
  15.     Bedford, MA  01730
  16.     USA
  17.     617-495-7107
  18.  
  19.     Unlimited non-commercial use is authorized.
  20.  
  21.     Compiled with Turbo C, large model.  MK_FP may be a problem with
  22.     other compilers.
  23.  
  24.     Additional routines needed:
  25.         ENVUTIL.C
  26.         MASTENV.ASM
  27. */
  28.  
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include <dos.h>
  33. #include "envutil.h"
  34.  
  35. /* This define makes the executable smaller
  36.  */
  37. #define fputs(x,y) bdosptr(9, x "$", 0)
  38.  
  39. int main(int argc, char **argv)
  40.     {
  41.     unsigned envseg;
  42.     char envstring[200];
  43.     char *iaca_ptr=MK_FP(0x40, 0xf0);
  44.  
  45.     if(argc < 2)
  46.         {
  47.         fputs("iacaread requires name of environment variable to set\n", stderr);
  48.         exit(1);
  49.         }
  50.  
  51.     strcpy(envstring, argv[1]);
  52.     strupr(envstring);                    /* Otherwise will put lower case in env. */
  53.     strcat(envstring, "=");
  54.     strncat(envstring, iaca_ptr, 16);
  55.  
  56.     if(NULL == (envseg = findenv()))
  57.         {
  58.         fputs("iacaread can't find environment!\n", stderr);
  59.         exit(1);
  60.         }
  61.  
  62.     envseg++;
  63.  
  64.     if (! envadd(envseg, envstring))
  65.         {
  66.         fputs("iacaread unable to add string to environment\n", stderr);
  67.         exit(1);
  68.         }
  69.  
  70.     return(0);
  71.     }
  72.